package com.cetc.sdp.kmga.cs.audit;

import com.cetc.sdp.kmga.cs.util.Tool;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * @description:
 * @author： DengQiang
 * @date: 2017/8/22 16:49
 */
public class IPSet implements Serializable {

    private String id;

    private String name;

    private Set<String> ipSet;

    private List<IpSeg> ipSegs;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Set<String> getIpSet() {
        return ipSet;
    }

    public void setIpSet(Set<String> ipSet) {
        this.ipSet = ipSet;
    }

    public List<IpSeg> getIpSegs() {
        return ipSegs;
    }

    public void setIpSegs(List<IpSeg> ipSegs) {
        this.ipSegs = ipSegs;
    }

    public static class IpSeg implements Serializable {
        private String start;
        private Long startLong;
        private String end;
        private Long endLong;

        public IpSeg(String start, String end) {
            this.start = start;
            this.startLong = Tool.getStringIpToLong(start);
            this.end = end;
            this.endLong = Tool.getStringIpToLong(end);
        }

        public String getStart() {
            return start;
        }

        public void setStart(String start) {
            this.start = start;
        }

        public Long getStartLong() {
            return startLong;
        }

        public void setStartLong(Long startLong) {
            this.startLong = startLong;
        }

        public String getEnd() {
            return end;
        }

        public void setEnd(String end) {
            this.end = end;
        }

        public Long getEndLong() {
            return endLong;
        }

        public void setEndLong(Long endLong) {
            this.endLong = endLong;
        }

        public boolean in(Long ip) {
            if (ip == null) {
                return false;
            }
            return ip >= this.startLong && ip <= this.endLong;
        }

        public boolean in(String ipString) {
            if (ipString == null) {
                return false;
            }
            return in(Tool.getStringIpToLong(ipString));
        }
    }
}
